package com.caiheng.api.service.titlemenu.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.caiheng.api.dao.titlemenu.TitleMenuSectionCityMapper;
import com.caiheng.api.entity.titlemenu.TitleMenuSectionCity;
import com.caiheng.api.entity.wxuser.User;
import com.caiheng.api.service.base.impl.BaseServiceImpl;
import com.caiheng.api.service.titlemenu.TitleMenuSectionCityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 行所显示的城市Service业务层处理
 *
 * @author ruoyi
 * @date 2022-12-10
 */
@Service
public class TitleMenuSectionCityServiceImpl extends BaseServiceImpl<TitleMenuSectionCityMapper, TitleMenuSectionCity> implements TitleMenuSectionCityService {

    @Resource
    private TitleMenuSectionCityMapper sectionCityMapper;

    @Override
    public TitleMenuSectionCity getSectionCityByCityName(int sectionId, User user) {
        if(user == null || (user !=null && StrUtil.isEmpty(user.getCity()))){
            return null;
        }
        QueryWrapper<TitleMenuSectionCity> qw = new QueryWrapper<>();
        qw.eq("menu_section_id",sectionId);
        qw.eq("city_name",user.getCity());
        qw.last("limit 1");
        return sectionCityMapper.selectOne(qw);
    }
}
